package com.platform.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.platform.entity.SysJobEntity;
import com.platform.service.SysJobService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

/**
 * 职位表Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-03-09 14:40:16
 */
@Controller
@RequestMapping("/sys/job")
public class SysJobController {
    @Autowired
    private SysJobService sysJobService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:job:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SysJobEntity> sysJobList = sysJobService.queryList(query);
        int total = sysJobService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sysJobList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{jobId}")
    @RequiresPermissions("sys:job:info")
    @ResponseBody
    public R info(@PathVariable("jobId") Long jobId) {
        SysJobEntity sysJob = sysJobService.queryObject(jobId);

        return R.ok().put("sysJob", sysJob);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:job:save")
    @ResponseBody
    public R save(@RequestBody SysJobEntity sysJob) {
        sysJobService.save(sysJob);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:job:update")
    @ResponseBody
    public R update(@RequestBody SysJobEntity sysJob) {
        sysJobService.update(sysJob);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:job:delete")
    @ResponseBody
    public R delete(@RequestBody Long[]jobIds) {
        sysJobService.deleteBatch(jobIds);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<SysJobEntity> list = sysJobService.queryList(params);

        return R.ok().put("list", list);
    }
}
